//
//  SetViewController.m
//  dangdang
//
//  Created by air on 16/1/25.
//  Copyright © 2016年 luweijie. All rights reserved.
//

#import "SetViewController.h"
#import "FeedbackViewController.h"
#import "RegisterViewController.h"
#import "PersonalViewController.h"

@interface SetViewController ()

@end

@implementation SetViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"设置";
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)setPushButtonArray:(UIButton *)sender {
    if (sender.tag == 0) {
        FeedbackViewController * feedbackboardVC = [[UIStoryboard storyboardWithName:@"FeedbackViewController" bundle:nil] instantiateViewControllerWithIdentifier:@"FeedbackViewController"];
        [self.navigationController pushViewController:feedbackboardVC animated:YES];
    }else if (sender.tag == 1){
        RegisterViewController * registerboardVC = [[UIStoryboard storyboardWithName:@"RegisterViewController" bundle:nil] instantiateViewControllerWithIdentifier:@"RegisterViewController"];
        registerboardVC.forgetString = @"change";
        [self.navigationController pushViewController:registerboardVC animated:YES];
    }else{
        NSFileManager *fileMger = [NSFileManager defaultManager];
        
        NSString * plistPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0]stringByAppendingPathComponent:@"usersList.plist"];
        
        //如果文件路径存在的话
        BOOL bRet = [fileMger fileExistsAtPath:plistPath];
        
        if (bRet) {
            
            NSError *err;
            
            [fileMger removeItemAtPath:plistPath error:&err];
            
            UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:nil message:@"退出成功" preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *action = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                userObject.userID = nil;
                userObject.type = nil;
                userObject.personString = nil;
                
                PersonalViewController * personboardVC = [[UIStoryboard storyboardWithName:@"PersonalViewController" bundle:nil] instantiateViewControllerWithIdentifier:@"PersonalViewController"];
                [self.navigationController pushViewController:personboardVC animated:YES];
            }];
            [alertVC addAction:action];
            [self presentViewController:alertVC animated:YES completion:nil];
        }
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
